package com.nuo.backend.modules.security.aspect;

import com.alibaba.fastjson.JSONArray;
import com.nuo.backend.common.utils.Constant;
import com.nuo.backend.common.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @description: TODO 清除 Menu 缓存
 * @author nuo
 * @date 2022/12/24 14:35
 * @version 1.0
 */
@Aspect
@Component
@Slf4j
public class SecMenuAspect {
	@Autowired
	private RedisUtils redisUtils;

	@Pointcut("@annotation(com.nuo.backend.modules.security.annotation.SecMenu)")
	public void secMenuPointCut() {
	}

	@After("secMenuPointCut()")
	public void clearRedisMenuCache(JoinPoint point) {
		log.info("执行: " + point.getTarget().getClass().getName() + "." + point.getSignature().getName() + "(" + JSONArray.toJSONString(point.getArgs()) + "), 清除 Redis 中 Menu 缓存");
		redisUtils.delete(Constant.SEC_MENU_KEY);
	}

}
